package ustc.xiaoyang.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ustc.xiaoyang.mapper.EmpMapper;
import ustc.xiaoyang.pojo.Emp;
import ustc.xiaoyang.pojo.Result;
import ustc.xiaoyang.pojo.dto.LoginDTO;
import ustc.xiaoyang.service.EmpService;

@RestController
@Slf4j
@RequestMapping("/login")
public class LoginController {
    private EmpService empService;
    public LoginController(EmpService empService) {
        this.empService = empService;
    }
    @PostMapping
    public Result login(@RequestBody Emp emp) {
        log.info("用户登录，username:{},password:{}", emp.getUsername(), emp.getPassword());
        LoginDTO loginDTO = empService.login(emp);
        if(loginDTO != null)
            return Result.success(loginDTO);
        return Result.error("用户名或密码错误");
    }
}
